#include <time.h>
#include <stdlib.h>
#include <stdio.h>

// 执行
int intervals = 1000;

// 计算pi
void calculate_pi(int interval) {
	
	unsigned int seed = time(NULL);
	int circle_points = 0;
	int square_points = 0;
	
	for (int i = 0; i < interval * interval; i++) {
		double rand_x = (double)rand_r(&seed) / RAND_MAX;
		double rand_y = (double)rand_r(&seed) / RAND_MAX;
		
		if (rand_x * rand_x + rand_y * rand_y <= 1) {
			circle_points++;
		}
		square_points++;
	}
	
	double pi = (double) (4 * circle_points) / square_points;
	
	printf("The estimated PI is: %1f in %d times\n", pi, interval * interval);
}

int main () {

	clock_t start, delta;
	double time_used;
	
	start = clock();
	
	double pi;
	
	for (int i = 0; i < 10; i++) {
		// 循环十次，可以认为是十个 task
		calculate_pi(intervals * (i + 1));
	}
	
	delta = clock() - start;
	printf("The time token in total: %1f seconds\n", (double) delta / CLOCKS_PER_SEC);
	
	return 0;
}

